package io.renren.modules.wx.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.wx.entity.ChapterEntity;
import io.renren.modules.wx.service.ChapterService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author linmingze
 * @email ${email}
 * @date 2022-10-14 19:06:40
 */
@RestController
@RequestMapping("wx/chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = chapterService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{chapterId}")
    public R info(@PathVariable("chapterId") Integer chapterId){
		ChapterEntity chapter = chapterService.getById(chapterId);

        return R.ok().put("chapter", chapter);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ChapterEntity chapter){
		chapterService.save(chapter);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ChapterEntity chapter){
		chapterService.updateById(chapter);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] chapterIds){
		chapterService.removeByIds(Arrays.asList(chapterIds));
        return R.ok();
    }


    /**
     * 根据courseId获取列表
     */
    @RequestMapping("/chapterlist/{courseId}")
    public R getList(@PathVariable("courseId") Integer courseId){
        List<ChapterEntity> entities = chapterService.getChapterByCourseId(courseId);
        return R.ok().put("list", entities);
    }
}
